package com.yl.ifanr.db;

import java.util.List;

import android.app.Activity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yl.ifanr.db.RssItemBean;
import com.yl.util.TimeUitl;
import com.yl.ifanr.R;

public class ItemlistAdapter extends BaseAdapter{
	public final String TAG = "ItemlistAdapter";
	
	private List<RssItemBean> itemBeanList;
	private Activity activity;
	
	public int getCount() {
		return itemBeanList.size();
	}
	
	public ItemlistAdapter(Activity activity,List<RssItemBean> itemBeanList) {
			this.itemBeanList = itemBeanList;
			this.activity = activity;
	}
	
	public View getView(final int position, View convertView, ViewGroup parent) {
		
		// 设定布局 the views from XML
		View rowView = convertView;
		
		if (rowView == null) {
			LayoutInflater inflater = activity.getLayoutInflater();
			try {
				rowView = inflater.inflate(R.layout.rss_list_item,null);
			} catch (Exception e) {
				// TODO: handle exception
				Log.e(TAG, e.getMessage());
			}
		}
		
		try {
			TextView titleTv = (TextView)rowView.findViewById(R.id.list_item_title);
			TextView createdTv = (TextView)rowView.findViewById(R.id.list_item_date);
			
			RssItemBean rssItemBean = this.itemBeanList.get(position);
			
			titleTv.setText(rssItemBean.getTitle());
			createdTv.setText(TimeUitl.TimeStamp2Date(rssItemBean.getPubdate()));
			rowView.setTag(rssItemBean);
		} catch (Exception e) {
			// TODO: handle exception
			Log.e(TAG, e.getMessage());
		}

		return rowView;
	}
	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}
}